package com.edaoe.interceptor;

import com.edaoe.common.Ret;
import com.edaoe.model.Authcode;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * Created by Dull on 2017/3/9 0009.
 */
public class AuthInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {
        Controller c = inv.getController();
        String code = c.getPara("authcode");
        Authcode authcode=Authcode.dao.findById(code);
        if (authcode==null){
            c.renderJson(Ret.error(-2));
        }else{
            c.setAttr("userId", authcode.getUserId());
            inv.invoke();
        }
    }
}
